import Vue from "vue";
import Vuex from "vuex";
import {getIndexData,getList} from "../api/index";
Vue.use(Vuex);
const store = new Vuex.Store({
  plugins: [],
  state: {
    indexData: {},
    listData: [],
  },
  mutations: {
    set: (state, { key, value }) => {
      state[key] = value;
    },
  },
  actions: {
    async getIndexData({ commit }) {
       await getIndexData().then(back=>{
        if(back.status==1){
            let data=back.data
            commit("set", {
              key: "indexData",
              value: data,
            });
        }
      });
    },
    async getList({ commit }, params) {
       await getList(params).then(back=>{
        if(back.status==1){
          let data=back.data;
          commit("set", {
            key: "listData",
            value: data,
          });
        }
      });
    },
    // async test() {
    //   await api.test();
    // },
  },
});

export default store;
